<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=3.0&ak=MLy2Xs1D6csnuwORcntVO6y8swoPnQ8R"></script>
</head>
<body onload="init()">

</body>
<script>
    function init() {
        var geolocation = new BMap.Geolocation();
        // 开启SDK辅助定位
        geolocation.enableSDKLocation();
        geolocation.getCurrentPosition(function (r) {
            var myGeo = new BMap.Geocoder();
            myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function (result) {
                if (result) {
                    alert(result.address)

                } else {
                    alert("定位失败，请手动输入地址")
                }
            });
        });
    }

</script>
</html>